 //应该是通过ajax请求过来的
 var showTree=(function(){

function showAllTree(json){
/*递归实现获取无级树数据并生成DOM结构*/
var str = "";
var forTree = function (o) {
    for (var i = 0; i < o.length; i++) {
        var urlstr = "";
        try {
            console.log(o[i]["url"]);
            if (typeof o[i]["url"] == "undefined") {
                urlstr = "<div class='tree-children'><span>" + o[i]["userLevel"] + o[i]["name"] + "</span><ul>";
            } else {
                urlstr = "<div class='tree-not-children'><span><a href=" + o[i]["url"] + ">" + o[i]["userLevel"] + o[i]["name"] + "</a></span><ul>";
            }
            str += urlstr;
            if (o[i]["children"] != null) {
                forTree(o[i]["children"]);
            }
            str += "</ul></div>";
        } catch (e) { }
    }
    return str;
}
/*添加无级树*/
document.getElementById("menuTree").innerHTML = forTree(json);

/*树形菜单*/
var menuTree = function () {
    //给有子对象的元素加
    $("#menuTree ul").each(function (index, element) {
        var ulContent = $(element).html();
        var spanContent = $(element).siblings("span").html();
        if (ulContent) {
            $(element).siblings("span").html(spanContent)
        }
    });

    $("#menuTree").find("div span").click(function () {
        var ul = $(this).siblings("ul");
        var spanStr = $(this).html();
        var spanContent = spanStr.substr(3, spanStr.length);
        if (ul.find("div").html() != null) {
            if (ul.css("display") == "none") {
                ul.show();
                //  $(this).html("[-]" + spanContent);
            } else {
                ul.hide();
                // $(this).html("[+] " + spanContent);
            }
        }
    })
}()

/*树形列表展开*/
$("#btn_open").click(function () {
    $("#menuTree ul").show();
    curzt("-");
})

/*收缩*/
$("#btn_close").click(function () {
    $("#menuTree ul").hide();
    curzt("+");
})
function curzt(v) {
    $("#menuTree span").each(function (index, element) {
        var ul = $(this).siblings("ul");
        var spanStr = $(this).html();
        var spanContent = spanStr.substr(3, spanStr.length);
        if (ul.find("div").html() != null) {
            $(this).html("[" + v + "] " + spanContent);
        }
    });
}
}
return {
    tree:showAllTree
}

})();